<template>
  <div>
    <ul>
      <li v-for="item in listData" :key="item.name">
        <i class="iconfont" :class="item.icon"></i>
        <div>
          <p class="wz">{{ item.name }}</p>
          <p class="sz">{{ item.count }}</p>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: {
    sonData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      listData: [
        {
          name: '今日销售量',
          count: 0,
          icon: 'icon-dingdan',
          flag: 'today_order_num'
        },
        {
          name: '今日销售额',
          count: 0,
          icon: 'icon-jinexianxing',
          flag: 'today_sale'
        },
        {
          name: '总销售量',
          count: 0,
          icon: 'icon-renwu',
          flag: 'total_order_num'
        },
        {
          name: '总销售额',
          count: 0,
          icon: 'icon-Dollar',
          flag: 'total_sale'
        }
      ]
    }
  },
  watch: {
    sonData: {
      handler() {
        // 当父组件把数据请求回来之后，把接收的 data 对象里面的四个属性，分别放置在数组的每一个对象里
        this.listData.forEach((item) => {
          item.count = this.sonData[item.flag]
        })
      },
      deep: true
    }
  }
}
</script>

<style lang="less" scoped>
ul {
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: space-between;

  li {
    flex: 0 0 21%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    // background-color: #ccc;
    padding: 20px;
    box-sizing: border-box;
    border-radius: 10px;
    color: #fff;
    i {
      font-size: 36px;
    }
    div {
      .wz {
        margin: 0;
        font-size: 16px;
        color: #eee;
        text-align: right;
        margin: 0 0 10px 0;
      }
      .sz {
        font-weight: bold;
        font-size: 18px;
        text-align: right;
        margin: 0;
      }
    }

    &:nth-of-type(1) {
      background: linear-gradient(45deg, #efff00, #ff4b22);
      i {
        color: #ff4b22;
      }
    }
    &:nth-of-type(2) {
      background: linear-gradient(45deg, #03f4de, #2196f3);
      i {
        color: #2196f3;
      }
    }
    &:nth-of-type(3) {
      background: linear-gradient(45deg, #ff2288, #8500ff);
      i {
        color: #8500ff;
      }
    }
    &:nth-of-type(4) {
      background: linear-gradient(45deg, #0072ff, #ff2222);
      i {
        color: #ff2222;
      }
    }
  }
}
</style>
